<template>
	<swiper
		v-if="!notFirst"
		class="width-100percent height-100percent"
		:duration="300"
		@animationfinish="animationFinishSwiper"
	>
		<swiper-item v-for="(n, index) in launchCount + 1" :key="n">
			<image
				v-if="index < launchCount"
				class="width-100percent height-100percent"
				:src="`/static/images/launch-${index + 1}.png`"
				mode="aspectFit"
			/>
		</swiper-item>
	</swiper>
</template>

<script lang="ts">
	import Vue from "vue";
	import Component from "vue-class-component";
	import { Storage } from "../libs/utils";

	@Component
	export default class Loading extends Vue {
		// component property

		launchCount: number = 4;
		notFirst: boolean = Boolean(Storage.get("baseData"));

		onLoad() {
			if (this.notFirst) {
				uni.showLoading({ title: "Loading...", mask: true });
				uni.reLaunch({
					url: `/pages/${
						Storage.get("userInfo")?.token
							? "tabs/home"
							: "common/authorization"
					}`,
					complete: uni.hideLoading,
				});
			}
		}

		onUnload() {
			uni.hideLoading();
		}

		animationFinishSwiper({ detail }: AnyObject) {
			if (detail.current === this.launchCount) {
				uni.showLoading({ title: "Loading..." });
				uni.redirectTo({
					url: `/pages/common/authorization`,
					complete: uni.hideLoading,
				});
			}
		}
	}
</script>


<style>
	page {
		width: 100%;
		height: 100%;
		background-color: #fff !important;
	}
</style>


<style lang="scss" scoped>
	// scss
</style> 